package com.haoting.mamba.match.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoting.mamba.match.entity.MatchInformationEntity;
import com.haoting.mamba.match.service.MatchInformationService;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.R;



/**
 * 
 *
 * @author tanghao
 * @email 767417609@qq.com
 * @date 2021-04-04 23:05:33
 */
@RestController
@RequestMapping("match/matchinformation")
public class MatchInformationController {
    @Autowired
    private MatchInformationService matchInformationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = matchInformationService.queryPage(params);

        return R.ok().put("page", page);
    }
    @GetMapping("/listDay")
    public R listDay() throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = formatter.parse("2021-04-07");
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,+1);
        String date2= formatter.format(calendar.getTime());
        Calendar calendar2 = new GregorianCalendar();
        calendar2.setTime(date);
        calendar2.add(calendar2.DATE,-1);
        String date3= formatter.format(calendar2.getTime());

        QueryWrapper<MatchInformationEntity> wrapper = new QueryWrapper<>();
        wrapper.like("match_date",formatter.format(date))
        .or()
        .like("match_date",date2)
        .or()
        .like("match_date",date3);
        QueryWrapper<MatchInformationEntity> wrapper2 = new QueryWrapper<>();
        wrapper2.like("match_date",date3);
        List<MatchInformationEntity> matchInformationEntities = matchInformationService.list(wrapper);
        List<MatchInformationEntity> matchInformationEntities2 = matchInformationService.list(wrapper2);
        int yesday = matchInformationEntities2.size();
        return R.ok().put("matchs",matchInformationEntities).put("yesdat",yesday);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		MatchInformationEntity matchInformation = matchInformationService.getById(id);

        return R.ok().put("matchInformation", matchInformation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MatchInformationEntity matchInformation){
		matchInformationService.save(matchInformation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MatchInformationEntity matchInformation){
		matchInformationService.updateById(matchInformation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		matchInformationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
